
using System;
using Gnome;
using Gdk;

namespace DiaCanvas
{
	public class Conector
	{
		private Figura _figure;
		
		private Point _Point;
		private Point _oldPoint;

		private bool _bIn;
		
		private CanvasLine _fig;
		
		private Gnome.Canvas _canvas;
		
		public DiaCanvas.Color _color;
		
		private bool _bDrag;
		
		
		
		public Conector(Figura fig, Gnome.Canvas c)
		{
			//if ( fig1 
	
						
			this._color.ForeGround = "#000000";
			this._color.BackGround = "#00ff00";
			
			this._canvas = c;
		}
		

		public string toString()
		{
			return "Este es un Conector";
		}
		
		public FiguraType Type { get { return DiaCanvas.FiguraType.Conector; } }		
		
		public void draw()
		{
			Console.WriteLine("Dibujando el Conector"); 
			
			this._fig = new Gnome.CanvasLine(this._canvas.Root());
			/*Point p1 = this._f1.GetPoint();
			Point p2 = this._f2.GetPoint();
			this._fig.Points = new CanvasPoints(new double[]{p1.X,p1.Y,p2.X,p2.Y}); 
			
			this._fig.CanvasEvent += new Gnome.CanvasEventHandler(CanvasEvent);
						
			//this._fig.OutlineColor = this._color;
			this._fig.FillColor = this._color;
       		this._fig.WidthPixels = 1;
       		this._fig.Show();
			
			*/
		}
		
		public void CanvasEvent(object obj, Gnome.CanvasEventArgs args)
		{
			//Console.WriteLine("Canvas Event");
			EventButton ev = new EventButton (args.Event.Handle);
			switch (ev.Type) 
			{
				case EventType.MotionNotify:
					if ( this._bDrag )
					{
						this._fig.Move(-this._oldPoint.X+ev.X,-this._oldPoint.Y+ev.Y);
						this._oldPoint.X = (int)ev.X;
						this._oldPoint.Y = (int)ev.Y;
					}
					break;
					
				case EventType.EnterNotify:
					//MouseEnter(obj,args);
					break;
	
					
				case EventType.LeaveNotify:
					//MouseLeave(obj,args);
					break;
	
				case EventType.DragEnter:
					Console.WriteLine("Drag Enter");
					break;
					
				case EventType.ButtonPress:
					if ( this._bIn )
					{
						this._bDrag = true;
						this._oldPoint.X = (int)ev.X;
						this._oldPoint.Y = (int)ev.Y;
					}
					break;
					
				case EventType.ButtonRelease:
					if ( this._bDrag )
					{
						this._fig.Move(-this._oldPoint.X+ev.X,-this._oldPoint.Y+ev.Y);
					}
					this._bDrag = false;
					break;
			}
			//Console.WriteLine(ev.Type.ToString());
		}

		public void ChangeColor()
		{
			
			//this._fig .OutLineColor = this._foreColor;
		}
		
	}
}
